﻿#ifndef BASEMODULE_IBASESIGNAL_H
#define BASEMODULE_IBASESIGNAL_H

#include <QObject>
#include <QString>
#include <QDomNodeList>
#include "API_BaseModule.h"
#include "GlobalEnums.h"

#define IBaseSignalInstance BaseModule::IBaseSignal::getInstance()

namespace CommandManager
{
    class CommandBase;
}
namespace BaseModule
{
    class API_BASEMODULE IBaseSignal : public QObject
    {
        Q_OBJECT
    public:
        static IBaseSignal* getInstance()
        {
            static IBaseSignal m_instance;
            return &m_instance;
        }

    signals:
        void signal_sendErrorMessageToUI(const QString& message);
        void signal_sendNormalMessageToUI(const QString& message, const QString& title = "");
        void signal_sendQuestionMessageToUI(int& result, const QString& title, const QString& message);

        /// @brief 打印类型信息到信息窗口
        /// @param msgType 消息类型
        /// @param content 消息内容
        void signal_showMessageToConsole(EMessageConsole msgType, QString content);

        /// @brief 使用代码手动关闭程序
        void signal_closeApp();

        /// @brief 准备关闭程序
        /// @param isClose 是否允许关闭. true允许，false禁止
        void signal_readyCloseApp(bool& isClose);

        void signal_refreshGenerateReportWindow();

        void signal_removeReportWidget(QString reportName);//删除窗口时，发信号从刷新界面的列表中移除

        void readDataFromProjectFile(QDomNodeList* nodeList);

        //脚本管理-------------------------------------------------------------------

        /// @brief 执行脚本管理
        /// @param type 脚本管理类型
        void signal_execScriptManager(BaseModule::EScriptManager type);

        /// @brief 执行python代码
        /// @param codes python代码数组
        /// @param save 是否保存
        /// @param exec 是否执行
        /// 执行时会自动保存
        void signal_execPYCode(QStringList codes, bool save = true, bool exec = true);

        /// @brief 执行一句脚本
        /// @param command 脚本命令 
        void signal_excuteScript(QString command);

        /// @brief 执行脚本文件
        /// @param filePath 文件路径
        /// @param isNoGui 是否是命令行模式
        /// @param listPara 参数列表
        /// @return 是否执行成功
        bool signal_execScriptFile(QString filePath, bool isNoGui, QStringList listPara = QStringList());

        /// @brief 保存脚本
        /// @param filePath 文件路径
        void signal_saveScript(QString filePath);

        /// @brief 编辑脚本
        /// @param filePath 文件内容
        void signal_editScript(QString filePath, QString text);

        /// @brief 执行案例脚本中的python代码
        /// @param listCode python代码列表
        void signal_execExampleScriptCode(QStringList listCode);

        /// @brief 执行python代码脚本，并且在脚本运行前执行一些其它python代码
        /// @param filePath 脚本文件路径
        /// @param listCode python代码列表
        void signal_execSmartScriptCode(QString filePath, QStringList listCode);

        /// @brief 设置python是否为调试模式
        /// @param isDebug 是否为调试模式
        void signal_setPythonIsDebug(bool isDebug);

        /// @brief Python脚本执行失败
        void signal_pythonExecFailed();

        /// @brief 更新状态栏信息
        /// @param text 信息
        /// @param isbegin 是否开始
        void signal_UpdateStatusBarInformation(QString text, bool isbegin);
        void signal_UpdateStatusBarInformationReport(QString text, bool isbegin);


        //脚本管理-------------------------------------------------------------------
        /// @brief 打开项目文件
        /// @param filePath 文件路径
        void signal_openProjectFile(QString filePath);
        /// @brief 保存项目文件
        /// @param filePath 项目文件路径
        void signal_saveProjectResult(QString filePath);

        /// @brief 粘贴项目树单个节点数据
        /// @param srcItemID 源itemID
        /// @param targetItemID 目标itemID
        void signal_pasteFileItemData(int srcItemID, int targetItemID);

        /// @brief 粘贴项目树文件夹节点数据
        /// @param srcItemID 源itemID
        /// @param targetItemID 目标itemID
        void signal_pasteDirectoryItemData(int srcItemID, int targetItemID);

        /// @brief 数据导入
        /// @param filePath 文件路径 
        /// @param isNeedPopupWindow 是否弹出窗口
        bool singal_toolButtonDataImport(QString filePath);

        /// @brief 清除项目所有数据
        void signal_clearCurrentProjectAllData();

        void signal_projectTreeSelectionChanged(QList<int> projectTreeSelctedRowIDList, bool* isSuccess);
        void signal_saveGraph(QString filePath, bool* isSuccess);
        void signal_set2DPlotType(int type);

        void signal_sendSelectedInfo(int& variableIndex, QList<QPair<int, QList<int>>>& chosenData, QList<int>& valueIndexs, bool* isSuccess, QList<int> selectParserIndex, bool isOpenNewWindow = true);
        void signal_setHeatMapSelectedCurveNameIndexs(int windowId, QList<int> selectedCurveNameIndexs);
        void signal_setHeatMapVariableAxisChanged(int windowId, int variableAxisIndex);
        void signal_setHeatMapSecondVariableAxisChanged(int windowId, int variableAxisIndex);
        void signal_setHeatMapCurveNameCheckStateChanged(int windowId, int curveNameIndex, bool checkState);
        void signal_setHeatMapDataOprationChanged(int windowId, bool isLoged, bool isNormalized);
        void signal_setHeatMapResultValueDataChanged(int windowId, int index);
        void signal_saveHeatMapMainSettingData(int windowId, bool scalarBarIsAutoRange, double scalarBarMin, double scalarBarMax,
                                               QString scalarBarColor, int scalarBarFontSize, bool XAxisAutoTitle, QString XAxisTitle, QString XTitleFontColor, int XTitleFontSize,
                                               QString XAxisColor, double XAisThickness, int XValuePrecision, QString XAxisDigitColor, int XAxisDigitSize,
                                               bool XAxisIsAutoRange, double XAxisMax, double XAxisMin, bool XIsAutoStepSize, double XCustomStepSize,
                                               bool YAxisAutoTitle, QString YAxisTitle, QString YTitleFontColor, int YTitleFontSize,
                                               QString YAxisColor, double YAisThickness, int YValuePrecision, QString YAxisDigitColor, int YAxisDigitSize,
                                               bool YAxisIsAutoRange, double YAxisMax, double YAxisMin, bool YIsAutoStepSize, double YCustomStepSize,
                                               bool gridIsMainGridLineDisplay, QString gridMainGridLineColor, int gridMainGridLineStyle, double gridMainGridLineThickness,
                                               bool gridIsSecondaryGridLineDisplay, QString gridSecondaryGridLineColor, int gridSecondaryGridLineStyle, double gridSecondaryGridLineThickness,
                                               QString windowTitleName, QString windowTitleFontColor, int windowTitleFontSize);
        void signal_setHeatMapFixedValueChanged(int windowId, QList<int> indexList);
        void signal_setHeatMapComplexPartsChanged(int windowId, bool isAmplitudeChecked, bool isPhaseChecked, bool isRealPartChecked, bool isImaginaryPartChecked);
        void signal_setHeatMapRemoveSelectedGraph(int windowId);
        void signal_setHeatMapRenameFinished(int windowId, QString name);
        void signal_setHeatMapAddTracer(int windowId, QString name, double x, double y, double value, int tracerStyle, int size, int penR, int penG, int penB, int penA, int interpolating, int curveInfoID, int tracerIndex);
        void signal_setHeatMapRemoveSelectedTracer(int windowId, QList<int> infoIdList);
        void signal_setHeatMapRemoveAllTracer(int windowId, QList<int> infoIdList);
        void signal_setHeatMapExportMarkerData(int mainWindowId, QString fileName);
        void signal_setHeatMapChangeTracerProperty(int windowId, QString name, int symbolStyle, int size, int penR, int penG, int penB, int penA, int tracerID);

        // 二维折线图
        void signal_lineChartSidebarVariableAxisChanged(int mainWindowId, QList<int> allSelectedItem, int reuslt, QString sVariableAxistCurrentText);
        void signal_lineChartSidebarCurveNameClicked(int mainWindowId, QList<int> allSelectedItemIndexList);
        void signal_lineChartSidebarCurveNameCheckStateChanged(int mainWindowId, int index, int checkStatus);
        void signal_lineChartSidebarFixedValueChanged(int mainWindowId, QList<int> sllIndexList);
        void signal_lineChartSidebarDataOperationChanged(int mainWindowId, bool isNormChecked, bool isDBChecked, bool isMathOperationChecked);
        void signal_lineChartSidebarValueDataChanged(int mainWindowId, int currentIndex);
        void signal_saveLineChartMainSettingData(int mainWindowId, int index, bool axiDisIsAutoName, QString axiDisTitleText, QString axiDisTitleFontColor, int axiDisTitleFontSize, QString axiDisAxisColor, int axiDisAxisThickness, double axiDisValuePrecision, QString axiDisAxisDigitColor, int axiDisAxisDigitSize,
                                                 bool axiRangIsAutoRange, double axiRangMaxValue, double axiRangMinValue, bool axiRangIsAutoStepSize, double axiRangCustomStepSize,
                                                 bool yAxiDisIsAutoName, QString yAxiDisTitleText, QString yAxiDisTitleFontColor, int yAxiDisTitleFontSize, QString yAxiDisAxisColor, int yAxiDisAxisThickness, double yAxiDisValuePrecision, QString yAxiDisAxisDigitColor, int yAxiDisAxisDigitSize,
                                                 bool yAxiRangIsAutoRange, double yAxiRangMaxValue, double yAxiRangMinValue, bool yAxiRangIsAutoStepSize, double yAxiRangCustomStepSize,
                                                 bool gridIsMainGridLineDisplay, QString gridMainGridLineColor, int gridMainGridLineStyle, double gridMainGridLineThickness, bool gridIsSecondaryGridLineDisplay, QString gridSecondaryGridLineColor, int gridSecondaryGridLineStyle, double gridSecondaryGridLineThickness,
                                                 QString titleName, QString titleFontColor, int titleFontSize,
                                                 QString legendFontColor, int legendFontSize, QString legendLineColor, int legendLineThickness,
                                                 QString resultDataName, QString dataLineColor, int dataLineStyle, double dataLineThickness, bool isDisplaySymbol, int symbolStyle, double symbolSize, QString symbolColor);

        // 极坐标图
        void signal_polarCoordinateGraphSidebarVariableAxisChanged(int mainWindowId, QList<int> allSelectedItem, int reuslt, QString sVariableAxistCurrentText);
        void signal_polarCoordinateGraphSidebarAllVariableAxisChanged(int mainWindowId, QString sVariableAxistCurrentText);
        void signal_polarCoordinateGraphSidebarCurveNameClicked(int mainWindowId, QList<int> allSelectedItemIndexList);
        void signal_polarCoordinateGraphSidebarCurveNameCheckStateChanged(int mainWindowId, int index, int checkStatus);
        void signal_polarCoordinateGraphSidebarDataOperationChanged(int mainWindowId, bool isNormChecked, bool isDBChecked);
        void signal_polarCoordinateGraphSidebarValueDataChanged(int mainWindowId, int currentIndex);
        void signal_savePolarCoordinateGraphMainSettingData(int mainWindowId, int index, QString angDisAxisColor, int angDisAxisThickness, double angDisValuePrecision, QString angDisAxisDigitColor, int angDisAxisDigitSize,
                                                            bool angRangIsAutoStepSize, double angRangCustomStepSize,
                                                            QString radDisAxisColorStr, int radDisAxisThickness, double radDisValuePrecision, QString radDisAxisDigitColorStr, int radDisAxisDigitSize,
                                                            bool radRangIsAutoRange, double radRangMaxValue, double radRangMinValue, bool radRangIsAutoStepSize, double radRangCustomStepSize,
                                                            bool gridIsMainGridLineDisplay, QString gridMainGridLineColor, int gridMainGridLineStyle, double gridMainGridLineThickness,
                                                            QString titleName, QString titleFontColor, int titleFontSize,
                                                            QString legendFontColor, int legendFontSize, QString legendLineColor, int legendLineThickness,
                                                            QString dataProResultDataName, QString dataProDataLineColor, int dataProDataLineStyle, double dataProDataLineThickness, bool dataProIsDisplaySymbol, int dataProSymbolStyle, double dataProSymbolSize, QString dataProSymbolColor);
        void signal_polarCoordinateGraphSidebarDeleteAllGraph(int mainWindowId);
        void signal_polarCoordinateGraphSidebarRenameSelectedGraph(int mainWindowId, QString name);
        void signal_polarCoordinateGraphSidebarComplexPartsChanged(int mainWindowId, bool isAmplitudeChecked, bool isPhaseChecked, bool isRealPartChecked, bool isImaginaryPartChecked);
        void signal_polarCoordinateGraphSidebarFixedValueChanged(int mainWindowId, QList<int> sllIndexList);
        void signal_polarCoordinateGraphSidebarRemoveSelectedGraph(int mainWindowId, QList<int> sllIndexList);
        void signal_polarCoordinateGraphSidebarCopySelectedGraph(int mainWindowId);
        void signal_polarCoordinateGraphAddTracer(int mainWindowId, QString name, double angle, int tracerStyle, int size, int penR, int penG, int penB, int penA,
                                                  int brushR, int brushG, int brushB, int brushA, int interpolating, int curveInfoID, int tracerIndex);
        void signal_polarCoordinateGraphRemoveSelectedTracer(int mainWindowId, QList<int> infoIdList, int curveInfoID);
        void signal_polarCoordinateGraphRemoveAllTracer(int mainWindowId, QList<int> infoIdList);
        void signal_polarCoordinateGraphExportMarkerData(int mainWindowId, QString fileName);
        void signal_polarCoordinateGraphChangeTracerProperty(int windowId, QString name, double x, int symbolStyle, int size, int penR, int penG, int penB, int penA, int tracerID);

        // 三维曲面图
        void signal_sendThreeDSurfacePlotData(int graphType, int variableIndex, int frequencyIndex, int readerIndex, QString filePath, QString name, QString geometryFileName, bool isOpenNewWindow);
        void signal_threeDSurfacePlotSidebarCurveNameClicked(int windowId, QList<int> selectedIndexes);
        void signal_threeDSurfacePlotSidebarFrequencyChanged(int windowId, int frequencyId);
        void signal_threeDSurfacePlotSidebarResultDataChanged(int windowId, int resultDataIndex);
        void signal_threeDSurfacePlotSidebarDataOprationChanged(int windowId, bool isLoged, bool isNormalized);
        void signal_threeDSurfacePlotSidebarCurveNameItemCheckStateChanged(int windowId, int itemIndex, bool checkState);
        void signal_saveThreeDSurfacePlotMainSettingData(int windowId, int settingDataId, bool scalarBarIsAutoRange, double scalarBarMin, double scalarBarMax,
                                                         bool scalarBarIsShowTitle, QString scalarBarTitle, QString scalarBarFontColor, int scalarBarFontSize,
                                                         int geometryTransparency, QString resultGraphName, int resultGraphModelTransparency, double resultGraphScale, bool cubeAxesIsVisible);
        void signal_saveThreeDSurfacePlotMoveResultDataSetting(int windowId, int infomationId, double translationX, double translationY, double translationZ,
                                                               double rotationTheta, double rotationPhi);
        void signal_delete3DSurfacePlots(int windowId, QString selectedIndexs);
        void signal_threeDSurfaceCurveNameItemRename(int windowId, int itemIndex, QString newName);
        void signal_threeDSurfaceCurveDataFileterRadioButtonClicked(int windowId, int index);

        // 三维云图
        void signal_sendThreeDCloudMapData(bool useNewWindow, int graphType, int variableIndex, int readerIndex, QString filePath, QString name, QString geometryFileName, int resultDataIndex);
        void signal_threeDCloudMapSidebarCurveNameClicked(int windowId, QList<int> selectedIndexes);
        void signal_threeDCloudMapSidebarUpdateFixedParameter(int windowId, int index);
        void signal_threeDCloudMapSidebarUpdateOriginalDataSource(int windowId, int index, int showType, int fixedValueIndex, bool isLog, bool isNormalize);
        void signal_threeDCloudMapSidebarResultDataChanged(int windowId, int index);
        void signal_threeDCloudMapSidebarNameItemRename(int windowId, int itemIndex, QString newName);
        void signal_threeDCloudMapSidebarDelete3DCloudMap(int windowId, QString selectedIndexs);
        void signal_threeDCloudMapSidebarDataOprationChanged(int windowId, bool isLoged, bool isNormalized);
        void signal_threeDCloudMapSidebarItemCheckStateChanged(int windowId, int itemIndex, bool visible);
        void signal_saveThreeDCloudMapMainSettingData(int windowId, int type, int settingDataId, bool scalarBarIsAutoRange,
                                                      double scalarBarMin, double scalarBarMax, bool scalarBarIsShowTitle,
                                                      QString scalarBarTitle, QString scalarBarFontColor, int scalarBarFontSize,
                                                      int geometryTransparency, QString resultGraphName, int resultGraphModelTransparency, bool cubeAxesIsVisible);

        // 表面电场图
        void signal_sendSurfaceElectricFieldGraphData(int graphType, int currentIndex, int readerIndex, QString sReaderType, QString sFilePath, QString sName, QString geometryFileName, bool isOpenNewWindow);
        void signal_surfaceElectricFieldMapSidebarCurveNameClicked(int windowId, QList<int> selectedIndexes);
        void signal_surfaceElectricFieldMapSidebarResultDataChanged(int windowId, int index);
        void signal_surfaceElectricFieldMapSidebarUpdateProcessData(int windowId, bool isLog, bool isNormalize);
        void signal_surfaceElectricFieldMapSidebarNameItemRename(int windowId, int itemIndex, QString newName);
        void signal_surfaceElectricFieldMapSidebarDeleteSurfaceElectricFieldMap(int windowId, QString selectedIndexs);
        void signal_surfaceElectricFieldMapSidebarItemCheckStateChanged(int windowId, int itemIndex, bool visible);
        void signal_saveSurfaceElectricFieldMapMainSettingData(int windowId, int type, int settingDataId, bool scalarBarIsAutoRange,
                                                               double scalarBarMin, double scalarBarMax, bool scalarBarIsShowTitle,
                                                               QString scalarBarTitle, QString scalarBarFontColor, int scalarBarFontSize,
                                                               int geometryTransparency, QString resultGraphName, int resultGraphModelTransparency, bool cubeAxesIsVisible);

        // 三维图标记
        void signal_savePostMarkerAddSettingData(int windowUniversalID, int infomationGraph3DBasicalId, int type,
                                                 int fieldIndex, QString fieldName, int pickedId, QString pickedValue);
        void signal_savePostMarkerRemoveChosenSettingData(int windowUniversalID, QString removeChosenId);
        void signal_savePostMarkerRemoveAllSettingData(int windowUniversalID);
        void signal_savePostMarkerExportTableData(int windowUniversalID, QString fileName);

        // 模型显示
        void signal_saveModelDisplaySettingData(int windowUniversalID, bool toolButtonActiveClipperIsChecked, bool toolButtonModelDisplayIsChecked, bool hasAnyGeometrySuccess);
        void signal_saveActiveClipperSettingData(int windowUniversalID, bool toolButtonActiveClipperIsChecked, bool toolButtonModelDisplayIsChecked, bool hasAnyGeometrySuccess, QString direction, double clipperValue);

        // 表格数据
        void signal_sendTableWidgetData(int readerIndex);
        void signal_hideOrShowTableColumn(int windowId, QString selectedIndex);
        void signal_changeTbColumnName(int windowId, int index, QString newName);
        void signal_flushTbBySelectedRow(int windowId, QString parms);
        void signal_exportTbData(int windowId, QString filePath, QString delimiter, int onlyVisible);
        void signal_highlightSelectedTbColumns(int windowId, QString parms);

        // 工程数据
        void signal_doPrjFileWrite(QString fileName);
        void signal_doPrjFileRead(QString fileName);

        void signal_doPrjCloseTree(int index);
        void signal_doPrjTreeCopyDir(int index);
        void signal_doPrjTreePasteDir(int srcId, int destId);
        void signal_doPrjTreeCopyData(int index);
        void signal_doPrjTreePasteData(int srcId, int destId);
        void signal_doPrjTreeExpandDir(int index);
        void signal_doPrjTreeCollapseDir(int index);
        void signal_closeCenterTableBar(int index);
        void signal_changeCurrentTabBar(int index);

        void signal_submitEvaluation(int windowId, int emulationType, QString parms);

        void signal_openProject();
        

        void signal_exportPstData(QString filePath);
        bool signal_importProjectData(QList<QString> filePaths);

        void signal_lineChartWindowSetIsEdit(bool state);
        void signal_lineChartChangeLineProperty(int windowUniversalID, int curveInfoID, QString docStr);
        void signal_centerWidgetTabWidgetCurrentChanged(int currentIndex);//
        void signal_lineChartLineChartTracerSelectChange(int id, bool selected);//
        void signal_lineChartLineChartStraightLineSelectChange(int id, bool selected);//
        void signal_lineChartCurve2DPlotorGuideLineSelectRemove();//
        void signal_lineChartCurve2DPlotorGuideLineAllRemove();//
        void signal_lineChartCurve2DPlotorMarkerSelectRemove();//
        void signal_lineChartCurve2DPlotorMarkerAllRemove();//
        void signal_lineChartWindowChangeGuideLineProperty(int guideLineID, double value, int guideLineStyle, double guideLineThickness, QString guideLineColor);//
        void signal_lineChartWindowChangeTracerProperty(int tracerID, QString tracerName, double x, int symbolStyle, double symbolSize, QString symbolColor);//
        void signal_lineChartAxisLineUpdate(QString typeAxis, int id, double value);//
        void signal_lineChartComputeHIRF(const QString& graphNames, double incidentWaveFieldValue, const QString& HIRFName, const QString& typeName, bool isCheckBoxChecked);//
        void signal_lineChartSidebarSettingsRemoveSelectedGraph();//
        void signal_lineChartSidebarSettingsDeleteAllCurve();//
        void signal_lineChartCreateLineChartStraightLine(int typeAxis);//
        void signal_lineChartMeasureButtonClicked(int meaureTypeInt, double value);//
        void signal_lineChartSidebarSettingsRenameCheck(QString text);//
        void signal_lineChartCenterWidgetMoveLegend(int dataInt);//
        void signal_lineChartWindowAddTracer(int windowUniversalID, QString parameters);//
        void signal_lineChartCenterWidgetDialogAddLocalRange(double rangeLower, double rangeUpper, QString selectNames, bool execFlag, bool edit);//
        void signal_lineChartCurve2DPlotorRemoveSelectedGraph();//
        void signal_lineChartCurve2DPlotorRemoveAllGraphs();//
        void signal_lineChartDialogCurveSmoothing(double range);//
        void signal_lineChartDialogWaveformAnalysis(QString graphName, double cutOffFrequency, QString filterType, int filterOrder, double leftBoundary, double rightBoundary, int windowId, QString resultList, bool isPythonRun = false); //
        void signal_lineChartSidebarSettingsAllVariableAxisSet(QString variableAxis);//
        void signal_lineChartSidebarSettingsComplex(QString complex); //
        void signal_lineChartSidebarSettingsFormulaEditor(QString data);//
        void signal_lineChartSidebarSettingsCopySelectedGraph();//
        void signal_lineChartComputeEffectiveness(QString graphNames, double e0);//
        void signal_lineChartDialogInterpolation(int number, int type);//
        void signal_lineChartCenterWidgetInfoListPaste(QString infoIds);//
        void signal_lineChartDialogTransferFunction(QString graphName, QString calibrationGraphName, QString type);//
        void signal_lineChartDialogIPLCalculation(QString IPLString);//

        void signal_removeImprotTextData(int itemID);
        void signal_textImportDataWriteConfig();
        void signal_textImportDataReadConfig();

        //命令管理-------------------------------------------------------------------

        /// @brief 执行命令
        /// @param command 命令
        /// @param state 状态，true成功，false失败
        void signal_execCommand(CommandManager::CommandBase* command, bool* state);

        /// @brief 执行命令管理
        /// @param commandType 命令类型
        void signal_execCommandManager(BaseModule::ECommandManager commandType);

        //命令管理-------------------------------------------------------------------

        //窗口鼠标状态变化
        void signal_updateWidgetCursor(Qt::CursorShape shap);
        void signal_resetWidgetCursor();

        // 波形分析
        void signal_sentWaveButterANdFFTVResult(int windowId, const QList<double>& resultList);

        void signal_saveGifSuccess(bool isSuc);

    private:
        IBaseSignal(const IBaseSignal&) = delete;
        IBaseSignal& operator=(const IBaseSignal&) = delete;
        IBaseSignal() = default;
    };

}

#endif
